﻿<?php
        ob_clean();

      $per_page =5;//固定每页显示的记录数
      $cur_page = empty($_GET['p'])?1:$_GET['p'];//获取地址栏的页码参数，当前访问的页面
      $offset = ($cur_page-1)*$per_page; //求出当前limit的偏移量
      $paget = getPages($link,'news',$per_page,$cur_page);//调用翻页函数

      //编写关联查询语句
      $sql = "select `news`.*,`cate`.`name` from `news`  inner join `cate` on `news`.type=`cate`.id order by `news`.id desc limit $offset,$per_page";
		  $result =mysqli_query($link,$sql);
		 	$data = array();//最终存储新闻表的所有数据数组
		 	while ($row = mysqli_fetch_assoc($result)) {
        $data[]=$row;
		 	}
      if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
          echo json_encode(array('data'=>$data,'paget'=>$paget)); die;
      }

     //视图加载页面
    include (VIEW_LAYER.'/admin/layout.html');

?>


